package com.pet.shop.controller.room;

import com.pet.shop.controller.BaseController;
import com.pet.shop.entity.room.Monitor;
import com.pet.shop.service.IBaseService;
import com.pet.shop.service.room.IMonitorService;
import com.pet.shop.utils.ApiResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.Map;

@RequestMapping("/web/monitor")
@Controller
public class MonitorController extends BaseController<Monitor>{

    @Autowired
    private IMonitorService monitorService;

    @Override
    public IBaseService<Monitor> getBaseService() {
        return monitorService;
    }

    /**
     *
     * @return
     */
    @RequestMapping("list")
    public ModelAndView list(){
        return new ModelAndView("room/monitorList");
    }

    @RequestMapping("/check")
    @ResponseBody
    public Map<String, Object> checkMonitor(HttpServletRequest request, Long monitorId){
        if(monitorId == null) return error("设备id必传");
        Monitor monitor = monitorService.checkMonitorVideo(monitorId);
        return ApiResultUtil.success_data(monitor);
    }


    @RequestMapping("/videoShow")
    @ResponseBody
    public ModelAndView videoShow(HttpServletRequest request, Long monitorId){
        Monitor monitor = monitorService.getEntity(monitorId);
        return new ModelAndView("room/videoShow").addObject("monitor", monitor);
    }
}
